package com.dc.web.controller;

import com.dc.dao.http.ElectricIdNameDao;
import com.dc.entity.http.ElectricIdNameEntity;
import com.dc.model.AjaxResult;
import com.dc.service.dto.IdNameDto;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 返回 id name 下拉框
 */
@Api(tags = "电Id-Name关系")
@RestController
@RequestMapping("/api/electric/common")
@Slf4j
public class ElectricCommonController {

    @Resource
    ElectricIdNameDao electricIdNameDao;


    @GetMapping("/list")
    public AjaxResult list() {

        List<ElectricIdNameEntity> all = electricIdNameDao.findAll();

        List<IdNameDto> collect = all.stream().map(t -> {
            return new IdNameDto(t.getMfId(), t.getName());
        }).collect(Collectors.toList());

        return AjaxResult.success(collect);
    }
}
